import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP
from lib.webui_permission import *
class c73300b:
    name = "验证登录功能-73300b"
    driver = webdriver.Firefox()

    def teststeps(self):
        self.driver.implicitly_wait(3)
        self.driver.get("http://172.17.66.19:8080/")

        STEP(2, '输入已注册的账号和错误密码，点击登录')
        input_username1 = self.driver.find_element(By.NAME, "username").send_keys('user4')
        input_psw1 = self.driver.find_element(By.NAME, "password").send_keys('888888')
        self.driver.find_element(By.CSS_SELECTOR, ".el-button").click()
        getted1 = False
        error_psw = ""
        # a = self.driver.find_element(By.CSS_SELECTOR, "body > div.el-message.el-message--error > p").text
        times = 0
        while error_psw != "用户名或密码错误":
            try:
                error_psw += self.driver.find_element(By.CLASS_NAME,
                                                      "el-message--error"
                                                      ).text
                getted1 = True
            except Exception:
                getted1 = False
                print(False)
                INFO(times)
                continue
            times += 1
        # time.sleep(2)
        expeted_error_psw_msg = "用户名或密码错误"
        CHECK_POINT("验证是否为期待文字", error_psw == expeted_error_psw_msg)
        self.driver.quit()